﻿using System;
using GraphProcessor;
using IQIGame.Onigao.Logic;
using UnityEngine;

namespace IQIGame.Onigao.GamePlay.Editors
{
    [System.Serializable, NodeMenuItem(SkillEditorConst.Battle + "/" + SkillEditorConst.Formula, typeof(SkillEditorGraph))]
    public class SkillFormulaNode : BaseNode
    {
        public override Color color => Color.cyan;
        
        [SerializeField] public int id;
        [SerializeField] public bool isFormula = true;

        [Input("公式")] public FormulaSetter Output;

        protected override void Process()
        {
            base.Process();
            var rConfig = new FormulaConfig()
            {
                value = this.id,
                isFormula = this.isFormula
            };
            this.Output?.SetFormula(rConfig);
        }
    }

    public class FormulaSetter
    {
        private Action<FormulaConfig> onSet;

        public FormulaSetter(Action<FormulaConfig> onSet)
        {
            this.onSet = onSet;
        }

        public void SetFormula(FormulaConfig rConfig)
        {
            this.onSet?.Invoke(rConfig);
        }
    }
}